﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.templates;
using MySql.Data.MySqlClient;
using System.Data;
using l1cs.server.utils;

namespace l1cs.server.datatables
{
    public class ArmorSetTable
    {
        private static Logger _log = Logger.getLogger( typeof( ArmorSetTable ).FullName );

        private static ArmorSetTable _instance;

        private List<L1ArmorSets> _armorSetList = new List<L1ArmorSets>();

        public static ArmorSetTable getInstance()
        {
            if ( _instance == null )
            {
                _instance = new ArmorSetTable();
            }
            return _instance;
        }

        /// <summary>
        /// セット防具のコンストラクター
        /// </summary>
        private ArmorSetTable()
        {/*TTOK*/
            DataTable dt;
            String sqlstr = "SELECT * FROM armor_set";
            using ( MySqlWrapper wrapper = new MySqlWrapper() )
            {
                dt = wrapper.GetDataTable(sqlstr);
            }
            foreach ( DataRow item in dt.Rows )
            {

                L1ArmorSets l1as = new L1ArmorSets();
                l1as.setId( SqlUtils.toInt( item["id"] ) );
                l1as.setSets( Convert.ToString( item["sets"] ) );
                l1as.setPolyId( SqlUtils.toInt( item["polyid"] ) );
                l1as.setAc( SqlUtils.toInt( item["ac"] ) );
                l1as.setHp( SqlUtils.toInt( item["hp"] ) );
                l1as.setMp( SqlUtils.toInt( item["mp"] ) );
                l1as.setHpr( SqlUtils.toInt( item["hpr"] ) );
                l1as.setMpr( SqlUtils.toInt( item["mpr"] ) );
                l1as.setMr( SqlUtils.toInt( item["mr"] ) );
                l1as.setStr( SqlUtils.toInt( item["str"] ) );
                l1as.setDex( SqlUtils.toInt( item["dex"] ) );
                l1as.setCon( SqlUtils.toInt( item["con"] ) );
                l1as.setWis( SqlUtils.toInt( item["wis"] ) );
                l1as.setCha( SqlUtils.toInt( item["cha"] ) );
                l1as.setIntl( SqlUtils.toInt( item["intl"] ) );
                l1as.setDefenseWater( SqlUtils.toInt( item["defense_water"] ) );
                l1as.setDefenseWind( SqlUtils.toInt( item["defense_wind"] ) );
                l1as.setDefenseFire( SqlUtils.toInt( item["defense_fire"] ) );
                l1as.setDefenseEarth( SqlUtils.toInt( item["defense_earth"] ) );

                _armorSetList.Add( l1as );
            }
        }

        public L1ArmorSets[] getAllList()
        {
            return _armorSetList.ToArray();
        }
    }
}
